using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;
public partial class Admin_DonHangChiTiet : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
        try
        {
            int iD = int.Parse(Request.QueryString["iD"].ToString());
            tbDonHang donhang = tbDonHangBUS.GetByID(iD);
            lit_MaDonHang.Text = donhang.MaDH.ToString();
            tbKhachHang khachhang = tbKhachHangBUS.GetByID(donhang.KhachHang);
            lit_KhachHang.Text = khachhang.HoTen;
            lit_NgayDatHang.Text = donhang.NgayDatHang.ToShortDateString();
            lit_NgayGiaoHang.Text = donhang.NgayGiaoHang.ToShortDateString();
            lit_TriGia.Text = donhang.TriGia.ToString();
            tbTinhTrangGH tinhtranggiaohang = tbTinhTrangGHBUS.GetByID(donhang.TinhTrangGH);
            lit_TinhTrangGiaoHang.Text = tinhtranggiaohang.TenTTGH.ToString();
            tbPhuongThucThanhToan phuongthucthanhtoan = tbPhuongThucThanhToanBUS.GetByID(donhang.PhuongThucThanhToan);
            lit_PhuongThucThanhToan.Text = phuongthucthanhtoan.TenPTTT.ToString();
            tbTinhTrangThanhToan tinhtrangthanhtoan = tbTinhTrangThanhToanBUS.GetByID(donhang.TinhTrangThanhToan);
            lit_TinhTrangThanhToan.Text = tinhtrangthanhtoan.TenTTTT.ToString();
            tbNhanVien nhanvien = tbNhanVienBUS.GetByID(donhang.NhanVienGiaoHang);
            lit_NhanVienGiaoHang.Text = nhanvien.TenNV.ToString();
            tbDiaDiem diadiem = tbDiaDiemBUS.GetByID(donhang.DiaChiGH);
            lit_DiaChiGiaoHang.Text = diadiem.DiaChi.ToString();

            Pager.PageSize = 5;
            Criteria c = new Criteria();
            c.add(Condition.AND, tbDonHangColumns.MaDH, Condition.EQUAL, iD);
            int total = 0;
            tbCTDonHangCollection ctdhCollection = tbCTDonHangBUS.Get(c.Criter, Pager.CurrentIndex, Pager.PageSize,
                tbCTDonHangColumns.MaCTDH.ToString(), OrderDirection.ASC.ToString(), out total);
            Repeater1.DataSource = ctdhCollection;
            Repeater1.DataBind();
            Pager.ItemCount = total;
            if (total <= Pager.PageSize)
            {
                Pager.Visible = false;
            }
        }
        catch
        {
            Response.Redirect("~/Admin/DonHangDanhSach.aspx");
        }
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            tbCTDonHang ctdonhang = (tbCTDonHang)e.Item.DataItem;
            Literal lit_SanPham = (Literal)e.Item.FindControl("lit_SanPham");
            tbSanPham sanpham = tbSanPhamBUS.GetByID(ctdonhang.SanPham);
            lit_SanPham.Text = sanpham.TenSP.ToString();
            Literal lit_ThanhTien = (Literal)e.Item.FindControl("lit_ThanhTien");
            double thanhtien = (ctdonhang.SoLuong * ctdonhang.DonGia);
            lit_ThanhTien.Text = thanhtien.ToString();
        }
    }
    protected void Pager_Command1(object sender, CommandEventArgs e)
    {
        Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
}
